/**
 * author:wos
 * time:2024-1-4
 * title:目录权限查询列表
 */
const {makeSqlSelect} = require('../../../utils/makeSql')
const parseQueryParams = require("../../../utils/parseQueryParams");

async function list(ctx, next) {
    const url = ctx.request.url
    const query = parseQueryParams(url)
    try {
        let postIds = [],roleIds = []
        if (query.userId){
            let postRs = await global.query(`SELECT * FROM sys_user_post WHERE userId = ${query.userId}`)
            for (let i in postRs){
                postIds.push(postRs[i].postId)
            }
            let roleRs = await global.query(`SELECT * FROM sys_user_role WHERE userId = ${query.userId}`)
            for (let i in roleRs){
                roleIds.push(roleRs[i].roleId)
            }
        }
        let posts = await global.query(`SELECT * FROM sys_post WHERE status = 0`)
        let roles = await global.query(`SELECT * FROM sys_role WHERE status = 0`)
        global.response(ctx, {
            "status":200,
            "code": 200,
            "data": {
                "postIds":postIds,
                "roleIds":roleIds,
                "posts":posts,
                "roles":roles
            },
            "msg":'success'
        })
    } catch (err) {
        global.serverError(ctx)
    }
}
module.exports = list


